package com.huaxia.day14.lock;

public class LockByObject {
    public static void main(String[] args) throws Exception {
        Thread t1 = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    add();
                }
            }
        };
        Thread t2 = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    add();
                }
            }
        };
        t1.start();
        t2.start();

        Thread.sleep(5000);
        System.out.println(Const.num);
    }

    static class Const {
        public static int num = 0;
    }

    public static  void add() {
        synchronized (LockByObject.class){
            Const.num++;
        }
    }
}
